
//校验
function regCheck(obj,reg){

    //判断值是否符合正则的规则
    //返回判断结果
    return reg.test(obj);
}

//校验用户名
function checkUsername(username) {

    //定义正则表达式 中文、英文、数字 4~10位
    let reg_username = /^(?!_)(?!.*?_$)[a-zA-Z0-9_\u4e00-\u9fa5]{4,10}$/;

    //返回 判断值是否符合正则表达式的规则
    return regCheck(username,reg_username);
}

//校验密码
function checkPassword(password){

    //定义正则表达式 字母+数字+特殊字符 至少8位
    let reg_password = /^(?![A-z0-9]+$)(?![A-z~@*()_]+$)(?![0-9~@*()_]+$)([A-z0-9~@*()_]{8,})$/;

    //返回 判断值是否符合正则表达式的规则
    return regCheck(password,reg_password);
}

//校验重复密码
function checkRePassword(Password,reEnterPassword){
    return Password === reEnterPassword;
}

//校验Email
function checkEmail(Email){

    //定义正则表达式
    let reg_email = /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;

    //返回 判断值是否符合正则表达式的规则
    return regCheck(Email,reg_email);
}

//校验手机号
function checkTelphone(Telphone){

    //定义正则表达式
    let reg_telphone = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;

    //返回 判断值是否符合正则表达式的规则
    return regCheck(Telphone,reg_telphone);
}

//checkbox检验
function checkCheckBox(checkbox){
    console.log(checkbox.is(':checked'))
    return checkbox.is(':checked');
}


//-------------------封装校验函数-----------
//username
function use(usernames, e){
    e.preventDefault();
    let username = $.trim(usernames.val());
    if(username !== ""){
        if(!checkUsername(username)){
            usernames.parent().parent().addClass("input_border");
            return false;
        }else {
            usernames.parent().parent().removeClass("input_border");
            return true;
        }
    }
}

//pwd
function pwd(passwords, e){
    e.preventDefault();
    let password = $.trim(passwords.val());
    if(password !== ""){
        if(!checkPassword(password)){
            passwords.parent().parent().addClass("input_border");
            return false;
        }else {
            passwords.parent().parent().removeClass("input_border");
            return true;
        }
    }

}

//re pwd
function rPwd(passwords, rePasswords, e){
    e.preventDefault();
    let password = $.trim(passwords.val());
    let rePassword = $.trim(rePasswords.val());
    if(password !== "" && rePassword !== ""){
        if(!checkRePassword(password, rePassword)){
            rePasswords.parent().parent().addClass("input_border");
            return false;
        }else {
            rePasswords.parent().parent().removeClass("input_border");
            return true;
        }
    }
}

//email
function clickEmail(emails, e){
    e.preventDefault();
    let email = $.trim(emails.val());
    console.log(email);
    if(email !== ""){
        if(!checkEmail(email)){
            emails.parent().parent().addClass("input_border");
            return false;
        }else {
            emails.parent().parent().removeClass("input_border");
            return true;
        }
    }

}

//agreement
function agreement(agreement, e){
    e.preventDefault();
    return checkCheckBox(agreement);
}

